﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NHAHANGLIENHOACHAY.SR_NHAHANG_BUS;
namespace NHAHANGLIENHOACHAY
{
    public partial class FormDangNhap :DevComponents.DotNetBar.Office2007Form
    {
        Service1SoapClient bus = new Service1SoapClient();
        public FormDangNhap()
        {
            InitializeComponent();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            NGUOIDUNG[] arraynd;
            arraynd = bus.LayDSNguoiDung();
            int flag = 0;
            if (txtMatKhau.Text != "" && txtDangNhap.Text != "")
            {
                //NguoiDungDTO user = new NguoiDungDTO();
                NGUOIDUNG dto = new NGUOIDUNG();
                for (int i = 0; i < arraynd.Length; i++)
                {
                    if (arraynd[i].TenDangNhap == txtDangNhap.Text && arraynd[i].MatKhau == txtMatKhau.Text)
                    {
                        //user = list[i];
                        dto = arraynd[i];
                        flag = 1;
                        break;
                    }
                }
                if (flag == 1)
                {
                    if (dto.LoaiTaiKhoan == "Quản lý")
                    {
                        //Hien thi form chinh
                        FormMain frm=new FormMain(dto);
                        frm.ShowDialog();
                        Close();
                        //Hide();
                        //FormAdminHome frm = new FormAdminHome();
                        //frm.ShowDialog();
                        //Close();
                    }
                    else
                    {
                        //Form user 
                        //Hide();
                        //FormUserHome usfrm = new FormUserHome();
                        //usfrm.ShowDialog();
                        FormUser fru = new FormUser(dto);
                        fru.ShowDialog();
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Đăng nhập sai!");
                }
            }
        }
    }
}
